//
//  StatusTopView.swift
//  sinaWeibo
//
//  Created by 张国梁 on 16/4/14.
//  Copyright © 2016年 CoderGL. All rights reserved.
//

import UIKit
import SnapKit

class StatusTopView: UIView {
    /// 微博数据
    var status: Status?{
        didSet{
            if let imagePath = status?.user?.profile_image_url {
                iconView.sd_setImageWithURL(NSURL(string: imagePath))
            }
            
            verifiedView.image = status?.user?.verifiedImage
            
            nameLabel.text = status?.user?.name
            nameLabel.textColor = status?.user?.mbrank>0 ? UIColor.orangeColor() : UIColor.blackColor()
            
            vipView.image = status?.user?.mbrankImage;
            
            timeLabel.text = status?.created_at
            
            sourceLabel.text = status?.source
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(iconView)
        addSubview(verifiedView)
        addSubview(nameLabel)
        addSubview(vipView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
    }
    
   
    override func layoutSubviews() {
        super.layoutSubviews()
        iconView.snp_updateConstraints { (make) in
            make.left.top.equalTo(margin)
            make.size.equalTo(CGSizeMake(iconH, iconH))
        }

        verifiedView.snp_updateConstraints { (make) in
            make.right.equalTo(iconView).offset(7)
            make.bottom.equalTo(iconView).offset(7)
        }
        
        nameLabel.xmg_AlignHorizontal(type: XMG_AlignType.TopRight, referView: iconView, size: nil, offset: CGPointMake(margin, 0))
        
        vipView.xmg_AlignHorizontal(type: XMG_AlignType.TopRight, referView: nameLabel, size: nil, offset: CGPointMake(margin, 0))
        
        timeLabel.xmg_AlignHorizontal(type: XMG_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPointMake(margin, 0))
        
        sourceLabel.xmg_AlignHorizontal(type: XMG_AlignType.TopRight, referView: timeLabel, size: nil, offset: CGPointMake(5, 0))
        
    }
    
    
    
    private lazy var iconView: UIImageView = {
        let view = UIImageView(image: UIImage(named: "avatar_default_big"))
        return view
    }()
    
    private lazy var verifiedView: UIImageView = {
        let view = UIImageView()
        view.frame.size = CGSizeMake(17, 17)
        return view
    }()
    
    private lazy var nameLabel = UILabel.label(UIColor.blackColor(), fontSize: 14)
    
    private lazy var vipView: UIImageView = {
        let view = UIImageView()
        view.frame.size = CGSizeMake(14, 14)
        return view
    }()
    
    private lazy var timeLabel = UILabel.label(UIColor.darkGrayColor(), fontSize: 10)
    
    private lazy var sourceLabel = UILabel.label(UIColor.darkGrayColor(), fontSize: 10)
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
